import { _range } from '@utils/functions';

export class Vector3 {
  public elements: Float32Array;

  constructor(elements?: Array<number>) {
    let v = new Float32Array(3);
    if (elements) {
      _range(3).forEach(i => v[i] = elements[i]);
    }
    this.elements = v;
  }

  public normalize() {
    const { elements: v } = this;
    const x = v[0], y = v[1], z = v[2];
    let inv = 1 / Math.sqrt(x * x + y * y + z * z);
    v[0] = x * inv;
    v[1] = y * inv;
    v[2] = z * inv;
    return this;
  }
}

export class Vector4 {
  public elements: Float32Array;

  constructor(elements?: Array<number>) {
    let v = new Float32Array(4);
    if (elements) {
      _range(4).forEach(i => v[i] = elements[i]);
    }
    this.elements = v;
  }

}
